function DigOut = Comp(vIn, vRef, vOs, PN)

% User: Armin Jalili
%
% Department of Electrical and Computer Engineering
% Isfahan University of Technology
% Updated by Armin Jalili
% Fri June 14 2013
%
    
% PN {0,1} is the pseudo random number used for chopping circuit,
% The comparator has two possible configurations:
DigOut1 = vIn + vOs > vRef; % when PN=1
DigOut2 = vIn - vOs > vRef; % when PN=0
DigOut = DigOut1 .* PN + DigOut2 .* (1 - PN);

    